home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / Fl_Multi_Label.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  2.6 KB  |  79 lines

  1. //
  2. // "$Id: Fl_Multi_Label.cxx,v 1.4 1999/01/07 19:17:23 mike Exp $"
  3. //
  4. // Multi-label widget for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Allows two labels to be used on a widget (by having one of them
  27. // be one of these it allows an infinte number!)
  28.  
  29. #include <FL/Fl.H>
  30. #include <FL/Fl_Widget.H>
  31. #include <FL/Fl_Menu_Item.H>
  32. #include <FL/Fl_Multi_Label.H>
  33.  
  34. static void multi_labeltype(
  35.     const Fl_Label* o, int x, int y, int w, int h, Fl_Align a)
  36. {
  37.   Fl_Multi_Label* b = (Fl_Multi_Label*)(o->value);
  38.   Fl_Label local = *o;
  39.   local.value = b->labela;
  40.   local.type = b->typea;
  41.   int W = w; int H = h; local.measure(W, H);
  42.   local.draw(x,y,w,h,a);
  43.   if (a & FL_ALIGN_BOTTOM) h -= H;
  44.   else if (a & FL_ALIGN_TOP) {y += H; h -= H;}
  45.   else if (a & FL_ALIGN_RIGHT) w -= W;
  46.   else if (a & FL_ALIGN_LEFT) {x += W; w -= W;}
  47.   else {int d = (h+H)/2; y += d; h -= d;}
  48.   local.value = b->labelb;
  49.   local.type = b->typeb;
  50.   local.draw(x,y,w,h,a);
  51. }
  52.  
  53. // measurement is only correct for left-to-right appending...
  54. static void multi_measure(const Fl_Label* o, int& w, int& h) {
  55.   Fl_Multi_Label* b = (Fl_Multi_Label*)(o->value);
  56.   Fl_Label local = *o;
  57.   local.value = b->labela;
  58.   local.type = b->typea;
  59.   local.measure(w,h);
  60.   local.value = b->labelb;
  61.   local.type = b->typeb;
  62.   int W = 0; int H = 0; local.measure(W,H);
  63.   w += W; if (H>h) h = H;
  64. }
  65.  
  66. void Fl_Multi_Label::label(Fl_Widget* o) {
  67.   Fl::set_labeltype(_FL_MULTI_LABEL, multi_labeltype, multi_measure);
  68.   o->label(_FL_MULTI_LABEL, (const char*)this);
  69. }
  70.  
  71. void Fl_Multi_Label::label(Fl_Menu_Item* o) {
  72.   Fl::set_labeltype(_FL_MULTI_LABEL, multi_labeltype, multi_measure);
  73.   o->label(_FL_MULTI_LABEL, (const char*)this);
  74. }
  75.  
  76. //
  77. // End of "$Id: Fl_Multi_Label.cxx,v 1.4 1999/01/07 19:17:23 mike Exp $".
  78. //
  79.